//
//  JHTabBarController.m
//  JHD_iOS
//
//  Created by 邓建 on 2018/7/31.
//  Copyright © 2018年 邓建. All rights reserved.
//

#import "JHTabBarController.h"

#import "JHBookWordViewController.h"  //教材单词
#import "JHMiddleWordViewController.h" //中考单词
#import "JHMiddleTutorViewController.h"  //中考辅导
#import "JHMineViewController.h"  //个人中心
#import "JHNavigationController.h"
#import "JHTabBar.h"

@interface JHTabBarController ()

@end

@implementation JHTabBarController

#pragma mark - 初始化
- (void)viewDidLoad {
    [super viewDidLoad];
    
    /**** 设置所有UITabBarItem的文字属性 ****/
    [self setupItemTitleTextAttributes];
    
    /**** 添加子控制器 ****/
    [self setupChildViewControllers];
    
    /**** 更换TabBar ****/
    [self setupTabBar];
}

/**
 *  设置所有UITabBarItem的文字属性
 */
- (void)setupItemTitleTextAttributes
{
    //设置默认的默认状态颜色
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:JK66TextColor,NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];
    
    //设置默认的选中状态颜色
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:JKMainColor, NSForegroundColorAttributeName,nil] forState:UIControlStateSelected];
}

/**
 *  添加子控制器
 */
- (void)setupChildViewControllers
{
    [self setupOneChildViewController:[[JHNavigationController alloc] initWithRootViewController:[[JHBookWordViewController alloc] init]] title:@"教材单词" image:@"教材单词1" selectedImage:@"教材单词"];
    
    [self setupOneChildViewController:[[JHNavigationController alloc] initWithRootViewController:[[JHMiddleWordViewController  alloc] init]] title:@"中考单词" image:@"中考单词" selectedImage:@"中考单词1"];
    
    [self setupOneChildViewController:[[JHNavigationController alloc] initWithRootViewController:[[JHMiddleTutorViewController alloc] init]] title:@"中考辅导" image:@"中考辅导" selectedImage:@"中考辅导1"];
    
    [self setupOneChildViewController:[[JHNavigationController alloc] initWithRootViewController:[[JHMineViewController alloc] init]] title:@"个人中心" image:@"个人中心" selectedImage:@"个人中心1"];
}

/**
 *  初始化一个子控制器
 *
 *  @param vc            子控制器
 *  @param title         标题
 *  @param image         图标
 *  @param selectedImage 选中的图标
 */
- (void)setupOneChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    vc.tabBarItem.title = title;
    if (image.length) { // 图片名有具体值
        vc.tabBarItem.image = [[UIImage imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    [self addChildViewController:vc];
}

/**
 *  更换TabBar
 */
- (void)setupTabBar
{
    [self setValue:[[JHTabBar alloc] init] forKeyPath:@"tabBar"];
}

@end
